<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>签到</title>
<link rel="stylesheet" type="text/css" href="/static/front/reward/css/common.css" />
<link rel="stylesheet" type="text/css" href="/static/front/reward/css/jqueryui.css" />
<script type="text/javascript" src="/static/front/reward/js/jqueryui.js"></script>
<script type="text/javascript" src="${_front_js}/layer/layer.js"></script>
</head>
<body style="margin:0px;">
<div id="document_bg" style="background-color:#2B2B2B;filter:alpha(opacity=50);-moz-opacity:0.5; -khtml-opacity: 0.5;opacity: 0.5;z-index:999;position: fixed;  ">
	

</div>
<div id="document_con" style=" display:none;">
   <div class="game-box">
       <div class="tigerBox" node-type="tiger">
        <div id="header">
        	<div id="turnplatewrapper" onselectstart="return false;" class="bgfix">
        		<div id="turnplate" class="bgfix">
				    
        			<div id="awards" class="bgfix"></div>
        			<div id="platebtn" class="bgfix"></div>
					<div id="closebtn" class="bgfix">&nbsp;</div>
        			<p id="msg"></p>
        			<p id="init" class="dn">初始化中，请稍后<span></span></p>
        		</div>
        	</div>
        	<div id="gift" class="bgfix"></div>
        </div>
        <div id="lotteryMsg" class="dn">
        	<p class="msg"></p>
        	<hr class="sp" />
        	<div class="content mv5">&ldquo;迅泊达,每日签到轮盘摇奖！&rdquo; 
        			<span class="option"></span>每日大转盘摇奖，轻松理财，惊喜不断，一等奖：500个积分，二等奖： 100个积分，三等奖：50个积分，百分百中奖！详情请登录<a href="/account/score">我的积分</a>查看。
        	</div>
        </div>
<!--新登录注册弹框-->
<!--<div id="new-login" class="dn"></div>-->
<input type="hidden" id="user_id" value="22">


<script type="text/javascript">
var turnplate = {
	turnplateBox : $('#turnplate'),
	turnplateBtn : $('#platebtn'),
	lightDom : $('#turnplatewrapper'),
	freshLotteryUrl : '',
	msgBox : $('#msg'),
	lotteryUrl : '',
	height : '414', //帧高度
	lightSwitch : 0, //闪灯切换开关. 0 和 1间切换
	minResistance : 5, //基本阻力
	Cx : 0.01, //阻力系数 阻力公式：  totalResistance = minResistance + curSpeed * Cx;	
	accSpeed : 15, //加速度
	accFrameLen : 40, //加速度持续帧数
	maxSpeed : 250, //最大速度 
	minSpeed : 20, //最小速度 
	frameLen : 6, //帧总数
	totalFrame : 0, //累计帧数,每切换一帧次数加1
	curFrame : 0, //当前帧
	curSpeed : 20, //上帧的速度
	lotteryTime : 0, //抽奖次数
	lotteryIndex : 5, //奖品index
	errorIndex : 4, //异常时的奖品指针
	initBoxEle : $('#turnplate #init'),
	progressEle : $('#turnplate #init span'),
	initProgressContent : '~~~^_^~~~', //初始化进度条的内容
	initFreshInterval : 500, //进度条刷新间隔
	virtualDistance : 10000, //虚拟路程,固定值，速度越快，切换到下帧的时间越快: 切换到下帧的时间 = virtualDistance/curSpeed
	isStop : false, //抽奖锁,为true时，才允许下一轮抽奖
	timer2 : undefined, //计时器
	initTime : undefined,
	showMsgTime : 2000, //消息显示时间
	lotteryChannel: '',

	channelList: {
		'login': '每日登录',
		'consume': '赚积分'
	},

	lotteryType : {
		'1个积分' : 0,	
		'50个积分' : 1,
		'100个积分' : 2,
		'10个积分' : 3,
		'再来一次' : 4,
		'500个积分' : 5
	},

	lotteryList : [
		'1个积分',
		'50个积分',		
		'100个积分',			
		'10个积分',		
		'再来一次',		
		'500个积分',	
	],

	lotteryDes : [
		'手气一般般，幸运指数半颗星！',
		'手气不错呢，幸运指数3颗星！',
		'手气无敌了，幸运指数4颗星！',
		'手气还可以，幸运指数2颗星！',
		'手气还凑合，幸运指数1颗星！',
		'手气太好了，幸运指数5颗星！',
	],

	//初始化
	init : function() {
		this.initAnimate()
		this.freshLottery();
		this.turnplateBtn.click($.proxy(function(){
			this.click();	
		},this));	
	},

	//初始化动画
	initAnimate : function() {
		this.initBoxEle.show();
		clearTimeout(this.initTimer);
		var curLength = this.progressEle.text().length,
			totalLength = this.initProgressContent.length;

		if (curLength < totalLength) {
			this.progressEle.text(this.initProgressContent.slice(0, curLength + 1));
		}else{
			this.progressEle.text('');
		}
		this.initTimer = setTimeout($.proxy(this.initAnimate, this), this.initFreshInterval);
	},

	//停止初始化动画
	stopInitAnimate : function() {
		clearTimeout(this.initTimer);
		this.initBoxEle.hide();
	},

	freshLotteryTime : function() {
		$('#top-menu').find('.lottery-times').html(this.lotteryTime);
	},

	//更新抽奖次数
	freshLottery : function() {
		this.stopInitAnimate();
		this.setBtnHover();
		this.isStop = true;
		this.lotteryTime = 1;
		this.freshLotteryTime();

	},

	//设置按钮三态
	setBtnHover : function() {
		//按钮三态
		$('#platebtn').hover(function(){
			$(this).addClass('hover');
		},function() {
			$(this).removeClass('hover click');
		}).mousedown(function(){
			$(this).addClass('click');
		}).mouseup(function(){
			$(this).removeClass('click');
		});	
	},

	//获取奖品
	lottery : function() {
        var result=0;
        $.ajax({
            type: 'POST',
            url: '/day/reward',
            dataType: 'json',
            cache: false,
            async:false,
            error: function(){
                alert('出错了！');
                return false;
            },
            success:function(data){
				if(data.code==-1){
					result=1;
					num=data.entity;
				}else if(data.code==1){
					layer.alert(data.msg,function(){
						window.location.href="/login";
						return false;
					});
				}else{
					layer.alert(data.msg,function(){
						$("#closebtn").click();
						window.location.reload();
						return false;
					});
				}			
            
            }

        });
        
        if(result==1){
	        this.lotteryIndex = num;
	        if(this.lotteryIndex!==false){
	            this.lotteryTime--;
	            this.freshLotteryTime();
	            this.totalFrame = 0;
	            this.curSpeed = this.minSpeed;
	            this.turnAround();
	            //this.lotteryIndex = typeof this.lotteryType[1] !== 'undefined' ? this.lotteryType[1] : this.errorIndex;
	            this.lotteryChannel = typeof this.channelList[1] !== 'undefined' ? this.channelList[1] : '';
	        }else{
	            alert('null');
	        }        
        }
	},

	//点击抽奖
	click : function() {
		//加锁时
		if(this.isStop == false) {
			this.showMsg('请不要重复点击');
			return;
		} 
		this.lottery();

	},

	//更新当前速度
	freshSpeed : function() {
		var totalResistance = this.minResistance + this.curSpeed * this.Cx;
		var accSpeed = this.accSpeed;
		var curSpeed = this.curSpeed;
		if(this.totalFrame >= this.accFrameLen) {
			accSpeed = 0;
		}
		curSpeed = curSpeed - totalResistance + accSpeed;

		if(curSpeed < this.minSpeed){
			curSpeed = this.minSpeed;
		}else if(curSpeed > this.maxSpeed){
			curSpeed = this.maxSpeed;
		}

		this.curSpeed  = curSpeed;
	},

	//闪灯,切换到下一张时调用
	switchLight : function() {
		this.lightSwitch = this.lightSwitch === 0 ? 1 : 0;
		var lightHeight = -this.lightSwitch * this.height;
		this.lightDom.css('backgroundPosition','0 ' + lightHeight.toString() + 'px');	
	},

	//旋转,trunAround,changeNext循环调用
	turnAround : function() {
		//加锁
		this.isStop = false;
		var intervalTime = parseInt(this.virtualDistance/this.curSpeed);		
		this.timer = window.setTimeout('turnplate.changeNext()', intervalTime);		
	},

	//弹出奖品
	showAwards : function(){
		$('#lotteryMsg').dialog('open');
	},

	//显示提示信息
	showMsg : function(msg, isFresh) {
		isFresh = typeof isFresh == 'undefined' ? false : true;
		if(typeof msg != 'string'){
			msg = '今天已经抽过奖了，明天再来吧';
		}
		var msgBox = this.msgBox;
		var display = msgBox.css('display');

		msgBox.html(msg);	

		window.clearTimeout(this.timer2);
		msgBox.stop(true,true).show();
		var fadeOut = $.proxy(function() {
			this.msgBox.fadeOut('slow');
		}, this);
		this.timer2 = window.setTimeout(fadeOut, this.showMsgTime);
	},


	//切换到下帧
	changeNext : function() {
	     
		//判断是否应该停止
		if(this.lotteryIndex !== undefined && this.curFrame == this.lotteryIndex && this.curSpeed <= this.minSpeed+10 && this.totalFrame > this.accFrameLen) {
			this.isStop = true;
			this.showAwards();
			return; 		
		}

		var nextFrame =  this.curFrame+1 < this.frameLen ? this.curFrame+1 : 0;
		var bgTop = - nextFrame * this.height;		
		this.turnplateBox.css('backgroundPosition','0 ' + bgTop.toString() + 'px');	
		this.switchLight();
		this.curFrame = nextFrame;
		this.totalFrame ++;
		this.freshSpeed();
		this.turnAround();
	}
}

</script>

<script type="text/javascript">
$("#closebtn").click(function(){  
       document.getElementById("document_bg").style.display="none";
       document.getElementById("document_con").style.display="none" ;  
});  

//登录插件
$('#lotteryMsg').dialog({
	modal: true,
	width: 500,
	height: 350,
	resizable: false,
	title: '获奖信息',
	autoOpen: false,
	open: function(){
			var showMsg = '您抽中了： ' + turnplate.lotteryList[turnplate.lotteryIndex] /*+ ' (来自:' + turnplate.lotteryChannel + ')'*/;
			var options = '今天抽中了' + turnplate.lotteryList[turnplate.lotteryIndex] + '，' + turnplate.lotteryDes[turnplate.lotteryIndex];
			$('#lotteryMsg').find('.msg').html(showMsg);
			$('#lotteryMsg').find('.option').html(options);
	},
	buttons: [{
		text:'关闭',
		click: function() {
			$(this).dialog('close');
			$("#closebtn").click();
		}
	},{
		text:'立即前往积分商城',
		click: function() {
            var jumpUrl = 'http://szd.svr.tw186.com:8089/good/list';
		    window.open(jumpUrl, "top");
			$(this).dialog('close');
		}
	}]
});

</script>
    
<!-- 抽奖 -->
</div>
</div>
    
</div>

</body>
</html>